﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace Web.Solist
{
    public partial class right_iframe : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Bind();
        }
        private void Bind()
        {
            DataSet ds = (new Controller.CorpInfoShow()).GetIndexMore(Web.AppCode.Sys_Config.GetCurrentCityCode());
            //餐饮美食
            DataView dvType1 = ds.Tables[0].DefaultView;
            dvType1.RowFilter = " TypeID = 1 ";
            dvType1.Sort = " Hits desc";
            dvType1 = GetTopDataViewRows(dvType1,4);
            rptCorpType1.DataSource = dvType1;
            rptCorpType1.DataBind();

            //夜场酒吧
            DataView dvType2 = ds.Tables[0].DefaultView;
            dvType2.RowFilter = " TypeID = 2 ";
            dvType2.Sort = " Hits desc";
            dvType2 = GetTopDataViewRows(dvType2, 4);
            rptCorpType2.DataSource = dvType2;
            rptCorpType2.DataBind();


            //休闲娱乐
            DataView dvType3 = ds.Tables[0].DefaultView;
            dvType3.RowFilter = " TypeID = 3 ";
            dvType3.Sort = " Hits desc";
            dvType3 = GetTopDataViewRows(dvType3, 4);
            rptCorpType3.DataSource = dvType3;
            rptCorpType3.DataBind();

            //度假旅游 
            DataView dvTyp4 = ds.Tables[0].DefaultView;
            dvTyp4.RowFilter = " TypeID = 4 ";
            dvTyp4.Sort = " Hits desc";
            dvTyp4 = GetTopDataViewRows(dvTyp4, 4);
            rptCorpType4.DataSource = dvTyp4;
            rptCorpType4.DataBind();

            //时尚购物 
            DataView dvTyp5 = ds.Tables[0].DefaultView;
            dvTyp5.RowFilter = " TypeID = 5 ";
            dvTyp5.Sort = " Hits desc";
            dvTyp5 = GetTopDataViewRows(dvTyp5, 4);
            rptCorpType5.DataSource = dvTyp5;
            rptCorpType5.DataBind();

            //资讯前线
            DataSet infoDs = (new Controller.InformationShow()).GetRight_Iframe(Web.AppCode.Sys_Config.GetCurrentCityCode());
            rptInfoList.DataSource = infoDs;
            rptInfoList.DataBind();

            DataSet couponds = (new Controller.CouponShow()).GetRight_iframe_top5(Web.AppCode.Sys_Config.GetCurrentCityCode());
            rptCouponList.DataSource = couponds;
            rptCouponList.DataBind();
        }
        private DataView GetTopDataViewRows(DataView dv, int n)
        {
            DataTable dt = dv.Table.Clone();

            for (int i = 0; i <= n - 1; i++)
            {
                if (i >= dv.Count)
                {
                    break;
                }
                dt.ImportRow(dv[i].Row);
            }

            return new DataView(dt, dv.RowFilter, dv.Sort, dv.RowStateFilter);
        }
    }
}
